﻿<% 
	response.setHeader("Pragma","No-cache");
	response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link
	href="${pageContext.request.contextPath}/views/js/ligerUI/skins/Aqua/css/ligerui-all.css"
	rel="stylesheet" type="text/css" />
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script
	src="${pageContext.request.contextPath}/views/js/ligerUI/js/core/base.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerTree.js"
	type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script> 
    <script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>

	
<script type="text/javascript">
	var tree = null;
	var dialog = frameElement.dialog;
	var manager = null;
	$(function() {
		var filetype = $('#filetype').val();
		var selid = $('#selid').val();
		tree = $("#tree1")
				.ligerTree(
						{
							url : '${pageContext.request.contextPath}/file/selectdepartmenttreeligerui?operation=1&filetype='+filetype+'&selid='+selid,
							ajaxType : 'get',
							childIcon:'folder',
							checkbox :false,
							isExpand : 2,
							nodeWidth:200,
							onSelect: onSelect
						});
		manager = $("#tree1").ligerGetTreeManager();
	});
	function contains(arr, obj) {
		  var i = arr.length;
		  while (i--) {
		    if (arr[i] == obj) {
		      return true;
		    }
		  }
		  return false;
		}

	function onSelect(note)
    {
		var loadedid = $('#loadedid').val();
		var shuzu = loadedid.split(',');
		//alert(shuzu+"*"+note.data.id);
		//alert(contains(shuzu,note.data.id));
		if(!contains(shuzu,note.data.id)){
			$.ajax({
				type : "post",
				url : '${pageContext.request.contextPath}/file/loaddepartfolders?departid='+note.data.id,
				data : {
				},
				dataType : "json",
				async: false,
				success : function(data) {
					//这里模拟一个加载节点的方法，append方法也用loadData(target,url)代替
		            manager.append(note.target, data );
					$('#loadedid').val(loadedid+','+note.data.id);
				},
				error : function() {
					alert("网络错误！");
				}
			});
		}
       	
            
    }
	
	function f_selectNode() {
		var a = tree.getSelected();
		if(a){
			//判断不能移动到原先的文件夹内
			var seltreepath = a.data.filePath;
			if(seltreepath==null){
				seltreepath = "/"+a.data.text;
			}else{
				seltreepath = "/"+a.data.text+seltreepath;
			}
			if(seltreepath==$('#selpath').val()){
				$.ligerDialog.warn('不能将文件移动到自身目录下');
				return;
			}
			
			var destFileId = null;
			var moveToDepartmentId = null;
			var nodeType = a.data.departOrFolder;
			if (nodeType == null || nodeType == undefined) {
				alert('无法判断节点类型');
			}
			//alert(nodeType);
			if (nodeType == '0') {//1是部门
				moveToDepartmentId = a.data.id;
				//alert(moveToDepartmentId);
			} else {
				destFileId = a.data.id;
				//alert(destFileId);
			}
			
			$.ajax({
				type : "post",
				url : "${pageContext.request.contextPath}/file/movefile",
				data : {
					"srcFileId":$('#selid').val(),
					"destFileId" : destFileId,
					"moveToDepartmentId" : moveToDepartmentId
				},
				dataType : "json",
				success : function(data) {
					if(data.code=='0'){
						parent.BindData(1);
						parent.$.ligerDialog.close();
						parent.operationTips('移动成功！');
					}else{
						$.ligerDialog.alert(data.msg);
					}
				},
				error : function() {
					alert("网络错误！");
				}
			});
			
		}else{
			//alert("请选择要移动要的位置");
			$.ligerDialog.warn('请选择要移动要的位置');
		}
	}
	
	

	function f_cancelSelect() {
		var parm = function(data) {
			return false;
		};

		tree.selectNode(parm);
	}
	
	function cancel(){
		dialog.close();//关闭dialog 
	}
</script>
</head>
<body style="padding: 10px">
	<input type="hidden" id="selid" value="${selid }"/>
	<input type="hidden" id="selpath" value="${selpath }"/>
	<input type="hidden" id="filetype" value="${filetype }"/>
	<input type="hidden" id="loadedid" value=""/>

	<div>
		<a class="l-button"
			style="width: 120px; margin-left: 10px; float: left;"
			onclick="f_selectNode()">确定</a>
		<a class="l-button"
			style="width: 120px; margin-left: 10px; float: left;"
			onclick="cancel()">取消</a>
	</div>
	<div
		style="width: 300px; height: 500px; margin: 10px; float: left; clear: both; border: 1px solid #ccc; overflow: auto;">


		<ul id="tree1" ></ul>
	</div>

	<div style="display: none"></div>
</body>
</html>
